package com.yuanwu.ncs.rabbitmq;

import jakarta.annotation.Resource;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

@Configuration
public class QueueConfig {

    public static final String NOTIFY_MSG_EXCHANGE = "notify_msg_exchange";
    //public static final String NOTIFY_MSG_QUEUE = "notify_msg_queue";

    public static final String NOTIFY_ROUTE_KEY = "NOTIFY_MSG_*";

    @Resource
    private Environment environment;

    @Bean
    public DirectExchange notifyMsgExe() {
        String exchangeName = NOTIFY_MSG_EXCHANGE + environment.getProperty("server.port");
        return new DirectExchange(exchangeName);
    }

    @Bean
    public Queue notifyMsgQueue() {
        String queueName = environment.getProperty("msg.consumer.queue");
        assert queueName != null;
        return new Queue(queueName, true);
    }


    @Bean
    public Binding notifyMsgQueueBinding() {
        return BindingBuilder
                .bind(notifyMsgQueue())
                .to(notifyMsgExe())
                .with(NOTIFY_ROUTE_KEY);
    }
}

